﻿using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Helper
{
    public class TFSHelper
    {

        public TFSHelper()
        {
            WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(@"C:\Projects\Akbank.InternetBanking.2010\Development\Source\Business\EDRAWebService\ConfigurationFiles\ResponseXmlSamples\bck\FishLotteryViewMCAResponse.xml");
            TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(info.ServerUri);

            Workspace workspace = info.GetWorkspace(tfs);

            var workItemList = tfs.GetService<WorkItemStore>();
            var developmentWorkItem = workItemList.GetWorkItem(3809);

            //var r = workspace.GetServerItemForLocalItem(@"C:\Projects\Akbank.InternetBanking.2010\Development\Source\Presentation\WebApplication.UI\default.aspx.cs");
            //workspace.PendAdd(@"C:\Users\AKN631p\Desktop\FileUpload.txt");

            //HesapOzetiDonemiciGoruntulemeMCAResponse

            var peddingChanges = workspace.GetPendingChanges();
            var testPedding = peddingChanges.Where(q => q.FileName == "FishLotteryViewMCAResponse.xml").ToArray();

            //peddingChanges.ToList().ForEach(q=> System.Diagnostics.Debug.WriteLine(q.FileName));
            //DevelopmentWorkItem.
            List<WorkItemCheckedInfo> WorkItemCheckedInfoLst = new List<WorkItemCheckedInfo>();

            WorkItemCheckedInfoLst.Add(new WorkItemCheckedInfo(3809, false, WorkItemCheckinAction.Associate));
            //    workspace.EvaluateCheckin(CheckinEvaluationOptions.All, peddingChanges, testpedding.ToArray(), "mca response xml", null, list.ToArray());

            //workspace.EvaluateCheckin(CheckinEvaluationOptions.All, peddingChanges, testpedding, "dene", null, list.ToArray());
            //workspace.CheckIn(testpedding, "MCA Sample Response", null, list.ToArray(), null);
            //workspace.CheckIn(testpedding,"fatih");


            //workspace.CheckIn(CheckinEvaluationOptions.All,"", "TFS Api Test", null, list.ToArray(), null,CheckinOptions.ValidateCheckinOwner);
            List<ItemSpec> ist = new List<ItemSpec>();

            //ist.Add(new ItemSpec(testpedding));
            WorkspaceCheckInParameters param = new WorkspaceCheckInParameters(ist.ToArray(), "fatih");

             List<CheckinNoteFailure> checkinNoteFailure=new List<CheckinNoteFailure>();


            
             VersionControlServer vs = tfs.GetService<VersionControlServer>();

             vs.NewPendingChange += vs_NewPendingChange;
             vs.PendingChangeCandidatesChanged += vs_PendingChangeCandidatesChanged;
             vs.PendingChangesChanged += vs_PendingChangesChanged;
             vs.UndonePendingChange += vs_UndonePendingChange;

             //workspace.PendAdd(@"C:\Projects\Akbank.InternetBanking.2010\Development\Source\Business\EDRAWebService\ConfigurationFiles\ResponseXmlSamples\bck\FishLotteryViewMCAResponse.xml");

         //    Console.WriteLine(this.GetHashCode().ToString());
             
         //   List< CheckinNoteFieldValue> checkinNoteList=new List<CheckinNoteFieldValue>();

         ////   checkinNoteFailure.Add(new CheckinNoteFailure(new CheckinNoteFieldDefinition("",false,10),"test"));
        
         //   var checkinNote=new CheckinNote(checkinNoteList.ToArray());

         //   var policyFailureList=new List<PolicyFailure>();
         //   policyFailureList.Add(new PolicyFailure("test3",null));

         //   var policy=new PolicyOverrideInfo("Test1",policyFailureList.ToArray());
           // workspace.CheckIn(testPedding, "", "TFS Api test", checkinNote, WorkItemCheckedInfoLst.ToArray(), policy,CheckinOptions.ValidateCheckinOwner);
        }

        void vs_UndonePendingChange(object sender, PendingChangeEventArgs e)
        {
            throw new NotImplementedException();
        }

        void vs_PendingChangesChanged(object sender, WorkspaceEventArgs e)
        {
            throw new NotImplementedException();
        }

        void vs_PendingChangeCandidatesChanged(object sender, WorkspaceEventArgs e)
        {
            throw new NotImplementedException();
        }

        void vs_NewPendingChange(object sender, PendingChangeEventArgs e)
        {
            
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

    }


}
